package com.niodata.md.rdb.model;

import java.util.List;
import lombok.Getter;
import lombok.Setter;

/**
 * rdb table info.
 */
@Getter
@Setter
public class Table {
  private String catalog;
  private String database;
  private String schema;
  private String type;
  private String name;
  private String remarks;
  private List<Column> columns;
  private String createSql;
  private List<ForeignKey> foreignKeys;
  private List<Index> indices;
  private long tableSize;
  private long indexSize;
  private List<View> views;
  private long rowCount;

  public String getSizeInMb() {
    return String.format("%.2f MB", tableSize / 1024.0 / 1024.0);
  }

  /**
   * get primary keys.
   *
   * @return primary keys
   */
  public List<String> getPrimaryKeys() {
    return columns != null && columns.size() > 0
        ? columns.stream().filter(Column::isPrimaryKey).map(Column::getName).toList() : List.of();
  }
}
